home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Low Level Languages / FORTRAN.500 / DISK6 / ANNUITY1.FO$ / ANNUITY1.bin
Encoding:
Text File  |  1991-04-15  |  2.0 KB  |  65 lines

  1. C
  2. C ANNUITY1.FOR - Generates annuity table. Contains intentional errors.
  3. C                Use with PWB section of "Environment & Tools" manual.
  4.       REAL*8      Pv, Rate, Pmt, RatePct
  5.       ONTEGER     Nper, ActNper
  6.  
  7. C
  8. C     Get input from the user.
  9. C
  10.       WRITE ( *, '(1X, A \)' ) 'Enter Present Value: '
  11.       READ ( *, * ) Pv
  12.       WRITE ( *, '(1X, A \)' ) 'Enter Interest Rate in Percent: '
  13.       READ ( *, * ) Rate
  14.       WRITE ( *, '(1X, A \)' ) 'Enter Number of Periods in Years:
  15.       READ ( *, * ) Nper
  16.  
  17. C
  18. C     Calculate periodic percentage as a fraction (RatePct),
  19. C     number of periods in months (ActNper). Then, calculate
  20. C     the monthly payment (Pmt).
  21. C
  22.       RatePct = Rate / 1200.0
  23.       ActNper = Nper * 12
  24.       Pmt = Pv * (RatePct / (1.0 - (1.0 / ((1.0 + RatePct) **
  25.      +      ActNper))))
  26.  
  27. C
  28. C     Write a summary of the annuity to the screen (*) device.
  29. C
  30.       WRITE( *,
  31.      +'( 1X, /,
  32.      +1X, 10HPrincipal:, T20, F13.2, /,
  33.      +1X, 14HInterest Rate:, T20, F13.2, /,
  34.      +1X, 16HNumber of Years:, T20, I13, /,
  35.      +1X, 16HMonthly Payment:, T20, F13.2, /,
  36.      +1X, 15HTotal Payments:, T20, F13.2, /
  37.      +1X, 15HTotal Interest:, T20, F13.2 )' )
  38.      +Pv, Rate, Nper, Pmt, Pmt * Nper * 12.0,
  39.      +Pmt * Nper * 12.0 - Pv
  40.  
  41. C
  42. C     Write headings for an amortization table to the screen
  43. C
  44.       WRITE( *, '(1X, /, 1X, 6HPeriod, 2X, 6H  Year, 2X, 9HPrincipal, 2X,
  45.      +                  9H Interest,
  46.      +                /, 1X, 6H------, 2X, 6H  ----, 2X, 9H---------, 2X,
  47.      +                  9H -------- )' )
  48.  
  49. C
  50. C     Loop for the actual number of periods printing the period, year,
  51. C     interest portion and principal portion of the payment
  52. C
  53.       DO iPeriod = 1, ActNper
  54.       PerInterest = Pv * RatePct
  55.       PerPrin = Pmt - PerInterest
  56.       WRITE( *, '(1X, I6, 2X, I6, 2X, F9.2, 2X, F9.2 )' )
  57.      +iPeriod,
  58.      +iPeriod / 12,
  59.      +PerPrin,
  60.      +PerInterest
  61.       Pv = Pv - PerPrin
  62.       END DO
  63.  
  64.       END
  65.